<%--
  Created by IntelliJ IDEA.
  User: 段某某
  Date: 2022/11/3
  Time: 9:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div class="modal-header">
    <button class="close" data-dismiss="modal">&times;</button>
    <h3>添加菜单</h3>
</div>
<form id="addmenus" class="form-horizontal">
    <!--身体-->
    <div class="modal-body">
        <div class="form-group">
            <label class="control-label col-md-2" for="name">父菜单名称:</label>
            <div class="col-md-10">
                <select id="parentid" name="parentid">
                    <option value="0">我就是爹</option>
                </select>
                <input type="hidden" name="seq" id="seq">
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-2" for="name">菜单名称:</label>
            <div class="col-md-10">
                <input type="text" id="name" name="name" class="form-control" placeholder="请输入菜单名称" required>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="tip">提示信息:</label>
            <div class="col-md-10">
                <input type="text" id="tip" name="tip" class="form-control" placeholder="请输入提示信息">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="descn">菜单说明:</label>
            <div class="col-md-10">
                <input type="text" id="descn" name="descn" class="form-control" placeholder="请输入菜单说明">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="imageurl">图片地址:</label>
            <div class="col-md-10">
                <input type="text" id="imageurl" name="imageurl" class="form-control" placeholder="请输入图片地址">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="linkurl">链接地址:</label>
            <div class="col-md-10">
                <input type="text" id="linkurl" name="linkurl" class="form-control" placeholder="请输入链接地址">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="target">目标窗口:</label>
            <div class="col-md-10">
                <input type="text" id="target" name="target" class="form-control" placeholder="请输入目标窗口">
                <input type="hidden" id="status" name="status" value="0">
            </div>
        </div>
    </div>
    <!--底部-->
    <div class="modal-footer">
        <div>
            <input type="submit" value="添加菜单" class="btn btn-info col-md-2 col-md-offset-2">
            <input type="reset" value="重置" class="btn btn-success col-md-2 col-md-offset-3">
            <input type="button" value="关闭" class="btn btn-danger col-md-2 col-md-offset-1">
        </div>
    </div>
</form>

<script>
    $(function () {
        $.ajax({
            url: "queryByMenusMenuid.action",
            type: "post",
            dataType: "json",
            success:function (data) {
                for(var i=0; i<data.length;i++){
                    var op=$("<option></option>")
                    op.val(data[i].id);
                    op.text(data[i].name);
                    $("#parentid").append(op);
                }
            }
        })
    })
    $("#addmenus").validate({
        messages:{
            parentid:"父菜单名称不能为空",
            name:"菜单名称不能为空",
        },
        submitHandler:function () {
            $("#addmenus").ajaxSubmit({
                url:"addmenus.action",
                type:"post",
                dataType:"json",
                success:function (data) {
                    alert(data.msg)
                    if(data.code==1){
                        location.href="addmenu.jsp";
                    }else {
                        location.href="menus.jsp";
                    }
                }
            })
        }
    })
</script>
</body>
</html>
